package main

import(
	"fmt"
	"time"
	"github.com/rxgo"
)
 
func main(){
	fmt.Printf("Debouce: ")
	rxgo.Just(0, 1, 2, 3, 4, 5).Map(func(x int) int {
		switch x {
			case 0:
				time.Sleep(0 * time.Millisecond)
			case 1:
				time.Sleep(1 * time.Millisecond)
			case 2:
				time.Sleep(3 * time.Millisecond)
			case 3:
				time.Sleep(3 * time.Millisecond)
			case 4:
				time.Sleep(1 * time.Millisecond)
			default:
				time.Sleep(1 * time.Millisecond)
		}
		return x
	}).Debounce(2 * time.Millisecond).Subscribe(func(x int) {
		fmt.Print(x)
	})
	fmt.Println()
	fmt.Printf("\nDistinct: ")

	rxgo.Just(1,2,3,4,5,6,7,8,9).Distinct().Subscribe(func (x int){
		fmt.Print(x)
	})
	fmt.Println()

	fmt.Printf("\nElementAt(3): ")
	rxgo.Just(1,2,3,4,5,6,7,8,9).ElementAt(3).Subscribe(func (x int){
		fmt.Print(x)
	})
	fmt.Println()

	fmt.Printf("\nFirst: ")
	rxgo.Just(1,2,3,4,5,6,7,8,9).First().Subscribe(func (x int){
		fmt.Print(x)
	})
	fmt.Println()

	fmt.Printf("\nIgnoreElements: ")
	rxgo.Just(1,2,3,4,5,6,7,8,9).IgnoreElements().Subscribe(func (x int){
		fmt.Print(x)
	})
	fmt.Println()

	fmt.Printf("\nLast: ")
	rxgo.Just(1,2,3,4,5,6,7,8,9).Last().Subscribe(func (x int){
		fmt.Print(x)
	})
	fmt.Println()

	fmt.Printf("\nSkip(4): ")
	rxgo.Just(1,2,3,4,5,6,7,8,9).Skip(4).Subscribe(func (x int){
		fmt.Print(x)
	})
	fmt.Println()

	fmt.Printf("\nSample: ")

	//time.Sleep(250 * time.Millisecond)
	rxgo.Just(0, 1, 2, 3, 4, 5).Map(func(x int) int {
		switch x {
		case 0:
			time.Sleep(0 * time.Millisecond)
		case 1:
			time.Sleep(1 * time.Millisecond)
		case 2:
			time.Sleep(3 * time.Millisecond)
		case 3:
			time.Sleep(3 * time.Millisecond)
		case 4:
			time.Sleep(1 * time.Millisecond)
		default:
			time.Sleep(1 * time.Millisecond)
		}
		return x
	}).Sample(2 * time.Millisecond).Subscribe(func(x int) {
		fmt.Print(x)
	})
	fmt.Println()

	fmt.Printf("\nSkipLast(4): ")

	rxgo.Just(1,2,3,4,5,6,7,8,9).SkipLast(4).Subscribe(func (x int){
		fmt.Print(x)
	})
	fmt.Println()

	fmt.Printf("\nTake(4): ")

	rxgo.Just(1,2,3,4,5,6,7,8,9).Take(4).Subscribe(func (x int){
		fmt.Print(x)
	})
	fmt.Println()

	fmt.Printf("\nTakeLast(4): ")
	rxgo.Just(1,2,3,4,5,6,7,8,9).TakeLast(4).Subscribe(func (x int){
		fmt.Print(x)
	})
	fmt.Println()

}


